package com.cti.ftpservice.ftp;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateHelper {

	public static void CompareDate(Date fromDate,Date toDate){
		if(fromDate==null)return;
		if(toDate==null)return;
		if(toDate.getTime()<fromDate.getTime()){
		//	Date tempDate=toDate;
			toDate=fromDate;
			fromDate=toDate;
		}
	}
	
	public static int getYearFromDate(Date Date){
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(Date);
		return calendar.get(Calendar.YEAR);
	}
	
	public static int getMonthFromDate(Date Date){
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(Date);
		return calendar.get(Calendar.MONTH+1);
	}
	
	public static int getDayFromDate(Date Date){
		Calendar calendar=Calendar.getInstance();
		calendar.setTime(Date);
		return calendar.get(Calendar.DAY_OF_MONTH);
	}
	
	public static Date getDate(int year,int month,int day){
		Calendar calendar=Calendar.getInstance();
		calendar.set(year, month, day);
		return calendar.getTime();
	}
	
	
	public static String toStirng(Date date,String pattern){
		if(date==null) return "";
		SimpleDateFormat dateFormat=new SimpleDateFormat(pattern);
		return dateFormat.format(date);
	}
	
	public static Date stringToDate(String dateString,String pattern){
		try  
		{  
		    SimpleDateFormat sdf = new SimpleDateFormat(pattern);  
		    return sdf.parse(dateString);  
		}  
		catch (Exception e)  
		{ 
		    System.out.println(e.getMessage());  
		}  
		return null;
	}
}
